package com.firebird.app.fekpsl.mvp.home

import com.firebird.app.fekpsl.constant.Constant
import com.firebird.app.fekpsl.ext.ss
import com.firebird.app.fekpsl.mvp.common.CommonPresenter
import com.firebird.app.fekpsl.utils.Preference
import com.firebird.fekpslan.mvp.model.HomeModel


/**
 * Created by firebird on 2018/4/21.
 */
class HomePresenter : CommonPresenter<HomeContract.Model, HomeContract.View>(), HomeContract.Presenter {

    override fun createModel(): HomeContract.Model? = HomeModel()

    override fun requestBanner() {
        mModel?.requestBanner()?.ss(mModel, mView, false) {
            mView?.setBanner(it.data)
        }
    }

    override fun requestWallList(pageNo: Int,userUuid:String) {
        mModel?.requestWallList(pageNo,userUuid)?.ss(mModel, mView, pageNo == 0) {
            mView?.setWallList(it.data)
        }
    }

    override fun requestHomeData() {
        val uuid:String by Preference(Constant.UUID_KEY, "")
        requestBanner()
        val observable = if (true) {
            mModel?.requestWallList(0,uuid)
        } else{
            mModel?.requestWallList(0,uuid)
        }
        observable?.ss(mModel, mView, false) {
            mView?.setWallList(it.data)
        }
    }

}